package praktikumid.kaug;

import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.util.ArrayList;
import java.util.List;

public class Lquend extends Canvas {

	List<Point> pts = new ArrayList<Point>();
	
	public Lquend() {
		addMouseMotionListener(new MouseMotionAdapter() {
			@Override
			public void mouseDragged(MouseEvent e) {
				Point pt = e.getPoint();
				System.out.println(pt);
				pts.add(pt);
				
				repaint();
			}
		});
	}
	
	@Override
	public void update(Graphics g) {
		paint(g);
	}
	
	@Override
	public void paint(Graphics g) {
		super.paint(g);
		
		Point from = null;
		for (Point p : pts) {
			
			if (from == null) {
				from = p;
				continue;
			}
			
			g.drawLine(from.x, from.y, p.x, p.y);
			
			// reset from!
			from = p;
		} // -for
	}
}
